{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=241
  Verdict: Accepted
}
uses 
	SysUtils, Math;
 
var
	i,j,ans:longint;
	a:array[0..30] of longint;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
for i:=1 to 20 do
	read(a[i]);
ans:=maxlongint;
for i:=1 to 19 do begin
	if a[i]=0 then continue;
	for j:=i+1 to 20 do
		if a[j]=0 then
			ans:=min(ans,j-i-1);
end;
if ans=maxlongint then ans:=-1;
write(ans);
end.